<?php

namespace App\Http\Requests\Admin\Finance;

use App\Models\Enum\DataType;
use Illuminate\Foundation\Http\FormRequest;

class CheckIndexRequest extends FormRequest
{
    public function __construct()
    {

    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'start_time' => 'before_or_equal:end_time',
            'end_time' => 'after_or_equal:start_date',
        ];
    }

    public function messages()
    {
        return [
            'start_time.before_or_equal' => '开始时间必须小于或等于结束时间',
            'end_time.after_or_equal' => '结束时间必须大于或等于开始时间',
        ];
    }

    protected function prepareForValidation()
    {
        $reqStartTime = isset($this->start_time) ? $this->start_time : date('Y-m-d');
        $reqEndTime = isset($this->end_time) ? $this->end_time : date('Y-m-d');

        $reqGameId = isset($this->game_id) ? $this->game_id : '';
        $reqChannelId = isset($this->channel_id) ? $this->channel_id : '';

        $this->merge([
            'start_time' => $reqStartTime,
            'end_time' => $reqEndTime,
            'game_id' => $reqGameId,
            'channel_id' => $reqChannelId,
        ]);
    }
}
